package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManageService;
import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author lifeihu
 * @date 2022/1/3
 * @TIME:18:33
 */
@RestController
@RequestMapping("/manage")
public class ManageController {
    @Autowired
    private ManageService manageService;
    //查看用户列表
    @GetMapping("/users")
    public ResponseEntity findUserByPage(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pageResult=manageService.findUserByPage(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }
    //查看用户资料
    @GetMapping("/users/{userId}")
    public ResponseEntity findUser(@PathVariable("userId") Long userId){
     UserInfo userInfo=manageService.findUser(userId);
     return ResponseEntity.ok(userInfo);
    }
    /**
     * 查询指定用户发布的所有视频列表
     */
    @GetMapping("/videos")
    public ResponseEntity findAllVideos(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize,
                                        Long uid){
        PageResult pageResult=manageService.findAllVideos(page,pagesize,uid);
        return ResponseEntity.ok(pageResult);
    }
    /**
     * 查询指定用户动态列表 */
    @GetMapping("/messages")
    public ResponseEntity findMessages(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pagesize,
                                       Long uid,Integer state){
         PageResult pageResult=manageService.findAllMovements(page,pagesize,uid,state);
         return ResponseEntity.ok(pageResult);
    }
    //用户冻结
    @PostMapping("/users/freeze")
    public ResponseEntity freeze(@RequestBody Map params){
        Map map =manageService.userFreeze(params);
        return ResponseEntity.ok(map);
    }
    //用户解冻
    @PostMapping("/users/unfreeze")
    public ResponseEntity unfreeze(@RequestBody  Map params) {
        Map map =  manageService.userUnfreeze(params);
        return ResponseEntity.ok(map);
    }
}
